<!-- 合作列表（我发起的、找我的合作） -->
<template>
  <a-card :bordered="false" class="br-10">
    <s-table
      ref="table"
      size="default"
      rowKey="id, enabled, title"
      :columns="columns"
      :data="loadData"
      :rowSelection="null"
    >
      <!-- 序号 -->
      <span slot="serial" slot-scope="text, record, index">
        {{ (pagination.current - 1) * pagination.pageSize + parseInt(index) + 1 }}
      </span>

      <!-- 申请状态 -->
      <span slot="pronum" slot-scope="text"> {{ text }}项 </span>
      <!-- 申请的项目列表 -->
      <span slot="projectName" slot-scope="text"> {{ text }} </span>

      <!-- 申请状态 -->
      <template slot="apStatus" slot-scope="text">
        <div>{{ apStatusMap[text] }}</div>
      </template>

      <!-- 操作按钮 -->
      <!-- <span slot="action" slot-scope="text, record">
        <a-button
          v-has="'business:cooperation:applyCooperation'"
          type="primary"
          ghost
          size="small"
          class="_mr-5"
          @click="handleToDetail(record)"
        >
          查看详情
        </a-button>
      </span> -->
    </s-table>
  </a-card>
</template>

<script>
import { STable } from '@/components'
import { CooperatedList, apStatusMap } from '@/api/business/cooperation'
export default {
  components: {
    STable,
  },
  data() {
    return {
      pagination: {
        current: 1,
        pageSize: 10,
      },
      queryParam: {
        orgName: undefined,
        apStatus: undefined,
      },
      columns: [
        {
          title: '合作机构',
          dataIndex: 'orgName',
          ellipsis: true,
        },
        {
          title: '合作项目',
          dataIndex: 'projectName',
          ellipsis: true,
          scopedSlots: { customRender: 'projectName' },
        },
        // {
        //   title: '操作',
        //   width: '150px',
        //   dataIndex: 'action',
        //   scopedSlots: { customRender: 'action' },
        // },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: async (parameter) => {
        var params = {
          current: parameter.pageNum,
          size: parameter.pageSize,
        }
        this.listLoading = true
        return CooperatedList(Object.assign(params, this.queryParam))
          .then((res) => {
            this.listLoading = false
            if (res.code === 0) {
              this.pagination.current = parameter.pageNum
              this.pagination.pageSize = parameter.pageSize
              return res
            } else {
              this.$message.error(res.msg)
            }
          })
          .catch((err) => {
            this.listLoading = false
            this.$message.error(err.msg)
          })
      },
      apStatusMap,
    }
  },
  created() {},
  methods: {
    handleToDetail(row) {
      this.$router.push({
        path: '/business/cooperation/applyCooperation',
        query: {
          data: JSON.stringify(row),
        },
      })
    },
  },
}
</script>
<style scoped lang="less">
</style>
